#ifndef __EVENT_INTERNAL_ZYS_HPP_
#define __EVENT_INTERNAL_ZYS_HPP_
#include <optional>
#include <tuple>
namespace event {

namespace internal {

template <typename TService> class Event {
public:
  using ServiceType = TService;
  Event() = default;
  Event(typename TService::TupleOfArgs args) : m_args(args) {}
  auto Call() {
    std::apply(
        [](auto... args) {
          if (TService::m_connection != nullptr) {
            TService::m_connection->DoCall(std::make_tuple(args...));
          }
        },
        m_args);
  }

  auto SetArgs(auto tuple_args) { m_args = std::make_optional(tuple_args); }
  auto operator=(Event &e) -> Event & {
    m_args = e.m_args;
    return *this;
  }
  auto GetArgs() const {
    if constexpr (std::tuple_size_v<typename TService::TupleOfArgs> == 1) {
      return std::get<0>(m_args);
    } else {
      return m_args;
    }
  }
  auto operator*() const { return GetArgs(); }

private:
  typename TService::TupleOfArgs m_args;
};

}; // namespace internal

} // namespace event

#endif